package indi.jp.project.business.pub.controller;

import indi.jp.project.business.pub.pojo.po.CompanyPO;
import indi.jp.project.business.pub.pojo.query.CompanyQuery;
import indi.jp.project.core.entity.JsonResult;
import indi.jp.project.business.pub.service.CompanyService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/pub/company")
public class CompanyController {

    @Resource
    private CompanyService companyService;

    @GetMapping("/queryGrid")
    public JsonResult queryGrid(CompanyQuery query, HttpServletRequest request) throws Exception {
        String account = request.getParameter("account");
        query.setLander(account);
        return companyService.queryGrid(query);
    }

    @PostMapping("/save")
    public JsonResult save(@RequestBody CompanyPO companyPO, HttpServletRequest request) throws Exception {
        String account = request.getParameter("account");
        companyPO.setCreateBy(account);
        companyPO.setModifyBy(account);
        return companyService.save(companyPO);
    }

    @PostMapping("/deleteById")
    public JsonResult deleteById(@RequestParam String id) throws Exception {
        return companyService.deleteById(id);
    }

    @GetMapping("findById")
    public JsonResult findById(@RequestParam String id) throws Exception {
        return companyService.findById(id);
    }
}
